package SaveServlet.teacher;

import com.lyq.bean.Teacher;
import com.lyq.bean.service.T_Service;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(
        name = "RemoveTeacher_Servlet",
        urlPatterns = {"/RemoveTeacher_Servlet"}
)
public class RemoveTeacher_Servlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public RemoveTeacher_Servlet() {
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        if (id.equals("seekall")) {
            List<Teacher> list = new ArrayList();
            list = (new T_Service()).seekAll_T(list);
            request.setAttribute("list", list);
            request.getRequestDispatcher("/jsp/teacher/m/RemoveTeacher.jsp").forward(request, response);
        } else if (id.equals("remove")) {
            String No = request.getParameter("No");
            String result = (new T_Service()).remove_T_With_Message(No);
            request.getSession().setAttribute("message", result);
            request.getSession().setAttribute("url", "RemoveTeacher_Servlet?id=seekall");
            response.sendRedirect("Message.jsp");
        }
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String select = request.getParameter("select");
        String seek = request.getParameter("seek");
        String name = request.getParameter("name");
        if (name != null || name == "") {
            List<Teacher> list = new ArrayList();
            list = (new T_Service()).seek_T(select, seek, name, list);
            request.setAttribute("list", list);
            if (list.size() >= 1 && list != null) {
                request.getRequestDispatcher("/jsp/teacher/m/RemoveTeacher.jsp").forward(request, response);
            } else {
                request.getSession().setAttribute("message", "未找到你要查询的内容！");
                request.getSession().setAttribute("url", "RemoveTeacher_Servlet?id=seekall");
                response.sendRedirect("Message.jsp");
            }
        }

    }
}